const { resolve } = require("path");
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  //入口
  entry: "./src/index.ts",
  //设置模式
  mode: 'development',
  //出口
  output: {
    path: resolve(__dirname, "build"),
    filename: "js/bundle.js",
    clean: true,
  },
  //loader 配置
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: "ts-loader",
      },
    ],
  },
  //在找不到文件的情况下, 自动添加如下后缀尝试加载文件
  resolve: {
    extensions: [".ts", ".tsx", ".js"],
  },
  //html 打包的插件设置
  plugins: [
    new HtmlWebpackPlugin({
      template: "./public/index.html",
    }),
  ],
  //开发服务
  devServer: {
    port: 3000,
    open: true,
  },
};
